#! /bin/bash
HIVE_HOME=/usr/bin/hive


${HIVE_HOME} -S -e "
use oe_dwd;
-- 对学生打卡事实表插入数据
insert into table dwd_fact_student_signin_record
select id,
       normal_class_flag,
       time_table_id,
       class_id,
       student_id,
       substr(signin_time, 1, 19) as signin_time,
       signin_date,
       inner_flag,
       signin_type,
       share_state,
       inner_ip
from oe_ods.ods_student_signin_record;

-- 对班级作息时间维度表插入数据
insert into table dwd_dim_class_time_table
select id,
       class_id,
       morning_template_id,
       morning_begin_time,
       morning_end_time,
       afternoon_template_id,
       afternoon_begin_time,
       afternoon_end_time,
       evening_template_id,
       evening_begin_time,
       evening_end_time,
       use_begin_date,
       use_end_date,
       substr(create_time, 1, 19) as create_time,
       create_person,
       remark
from oe_ods.ods_class_time_table;

-- 对班级排课维度表插入数据
insert into table dwd_dim_course_table_upload_detail
select id,
       base_id,
       class_id,
       class_date,
       content,
       teacher_id,
       teacher_name,
       job_number,
       classroom_id,
       classroom_name,
       is_outline,
       class_mode,
       is_stage_exam,
       is_pay,
       tutor_teacher_id,
       tutor_teacher_name,
       tutor_job_number,
       is_subsidy,
       answer_teacher_id,
       answer_teacher_name,
       answer_job_number,
       remark,
       substr(create_time, 1, 19) as create_time
from oe_ods.ods_course_table_upload_detail;

-- 对在读学员人数维度表插入数据
insert into table dwd_dim_class_studying_student_count
select *
from oe_ods.ods_class_studying_student_count;

-- 对学生请假事实表插入数据
insert into table dwd_fact_student_leave_apply
select id,
       class_id,
       student_id,
       audit_state,
       audit_person,
       substr(audit_time, 1, 19)  as audit_time,
       audit_remark,
       leave_type,
       leave_reason,
       substr(begin_time, 1, 19)  as begin_time,
       begin_time_type,
       substr(end_time, 1, 19)    as end_time,
       end_time_type,
       days,
       cancel_state,
       substr(cancel_time, 1, 19) as cancel_time,
       old_leave_id,
       leave_remark,
       valid_state,
       substr(create_time, 1, 19) as create_time
from oe_ods.ods_student_leave_apply;

insert into table dwd_calendar
select id,
       datelist,
       year(datelist) as year_code,
       month(datelist) as month_code
from oe_ods.ods_calendar;"